var styles = eval('(${styles})');                

function updateStyleSelect() {
    var selectedLanguage = getSelectedLanguage();
    
    var styleSelect = document.getElementById('style');
    while (styleSelect.options.length > 0) 
        styleSelect.options[0] = null;

    if (selectedLanguage == '') {
        styleSelect.options[0] = 
            new Option('Select language first...');
        return;
    };
    
    var newOptions = eval('styles.' + selectedLanguage);
    for (var i = 0; i < newOptions.length; i++) {
        var opt = newOptions[i];
        styleSelect.options[i] = new Option(opt.label, opt.value);
    } 
}

function getSelectedLanguage() {
    var languageSelect = document.getElementById('language');
    var selectedIndex = languageSelect.selectedIndex;
    return languageSelect.options[selectedIndex].value;
}

function validate() {
    if (getSelectedLanguage() == '') {
        alert('Please, select the language before submitting');
        return false;
    }
    return true;
}